import Vue from 'vue';
import Router from 'vue-router';
import store from '../store';

Vue.use(Router);

const Home = (resolve) => {
    import('components/home/home').then((module) => {
        resolve(module);
    });
};
const Anywhere = (resolve) => {
    import('components/anywhere/anywhere').then((module) => {
        resolve(module);
    });
};
const Cooperation = (resolve) => {
    import('components/cooperation/cooperation').then((module) => {
        resolve(module);
    });
};
const Cameraman = (resolve) => {
    import('components/cameraman/cameraman').then((module) => {
        resolve(module);
    });
};
const Technology = (resolve) => {
    import('components/technology/technology').then((module) => {
        resolve(module);
    });
};
const ContactUs = (resolve) => {
    import('components/contact-us/contact-us').then((module) => {
        resolve(module);
    });
};
const OurInfo = (resolve) => {
    import('components/ourInfo').then((module) => {
        resolve(module);
    });
};

const router = new Router({
    mode: 'history',
    // base: '/wedding',
    routes: [
        {
            path: '/wedding',
            component: Home
        },
        {
            path: '/wedding/home',
            name: 'home',
            component: Home
        },
        {
            path: '/wedding/anywhere',
            name: 'anywhere',
            component: Anywhere
        },
        {
            path: '/wedding/technology',
            name: 'technology',
            component: Technology
        },
        {
            path: '/wedding/cooperation',
            name: 'cooperation',
            component: Cooperation
        },
        {
            path: '/wedding/cameraman',
            name: 'cameraman',
            component: Cameraman
        },
        {
            path: '/wedding/contactUs',
            name: 'contactUs',
            component: ContactUs
        },
        {
            path: '/wedding/ourInfo',
            name: 'ourInfo',
            component: OurInfo
        }
    ]
});
let timer;
router.beforeEach(function (to, from, next) {
    timer = setTimeout(() => {
        store.commit('SET_ISLOADING', true);
    }, 200);
    next();
});

router.afterEach(function (to) {
    clearTimeout(timer);
    store.commit('SET_ISLOADING', false);
});

export default router;
